package cn.nfwx.tv.manager;

import android.content.Context;

import cn.nfwx.tv.callback.ResponseListener;
import cn.nfwx.tv.callback.ResponseWithFailListener;
import cn.nfwx.tv.controller.ShortVideoShareViewController;
import cn.nfwx.tv.okhttp.CustomOkHttpClient;
import cn.nfwx.tv.okhttp.UrlHelper;
import cn.nfwx.tv.util.LogUtil;
import okhttp3.Callback;

/**
 * Created by zhouzechao on 2017/11/24.
 */

public class ShortVideoManager {

    /**
     * 获取分享的视频地址
     *
     * @param context
     * @param playVsid
     * @param startTime
     * @param endTime
     * @param callBack
     * @return
     */
    public static String requestShortVideo(Context context, String playVsid, long startTime, long endTime, ResponseListener callBack) {
        String request_tag = "requestTimelineVideoPath";
        CustomOkHttpClient.cancleAll(request_tag);
        String url = UrlHelper.getShortVideoUrl(playVsid, startTime, endTime);
        LogUtil.e(ShortVideoShareViewController.class.getSimpleName(), url);
        CustomOkHttpClient.postObjectRequest(context, url, request_tag, callBack);
        return request_tag;
    }

    /**
     * 下载短视频
     *
     * @param playVsid  播放流id
     * @param startTime 回调(progress: 下载进度)
     * @param endTime
     * @param callBack  回调(finish: 是否下载完成)
     */
    public static String downloadShortVideo(Context context, String playVsid, long startTime, long endTime, Callback callBack) {
        String request_tag = "downloadShortVideo" + startTime;
        CustomOkHttpClient.cancleAll(request_tag);
        String url = UrlHelper.getDownloadShortVideoUrl(playVsid, startTime, endTime);
        CustomOkHttpClient.doGet(url, request_tag, callBack);
        return request_tag;
    }

    /**
     * 获取短视频地址
     *
     * @return
     */
    public static String requestIjkShortVideo(Context context, String gid, String startTime, String endTime, ResponseWithFailListener callBack) {
        String request_tag = "requestIjkShortVideo";
        CustomOkHttpClient.cancleAll(request_tag);
        String url = UrlHelper.getIjkShortVideoUrl(gid, startTime, endTime);
        CustomOkHttpClient.getObjectRequest(context, url, request_tag, callBack);
        return request_tag;
    }

    /**
     * 新的分享链接
     *
     * @param context
     * @param callBack
     * @return
     */
    public static String requestNewShareUrl(Context context, ResponseListener callBack) {
        String request_tag = "requestNewShareUrl";
        CustomOkHttpClient.cancleAll(request_tag);
        String url = UrlHelper.getNewShareUrl();
        CustomOkHttpClient.postObjectRequest(context, url, request_tag, callBack);
        return request_tag;
    }
}
